package com.yunche.yunchebusiness.utils.transpager;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

    /**
     * 根据当前年月(yyyy-MM)获取上一月或者下月
     * @param currentDate
     * @param pre  1：下一个   -1上一月
     * @return
     */
    public static int[] getLastDate(String currentDate,int pre) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(currentDate + "-" + "01");
        } catch (ParseException e) {
            e.printStackTrace();
        }

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.MONTH, pre);

        int[] dates = new int[2];
        dates[0] = c.get(Calendar.YEAR);
        dates[1] = c.get(Calendar.MONTH) + 1;


        return dates;

    }


    /**
     * 获取当前日期格式
     * @return
     */
    public static String getNow(String type){
        SimpleDateFormat sdf = new SimpleDateFormat(type);
        return sdf.format(new Date());
    }
    /**
     * string 转date
     * @return
     */
    public static Date getFormatDate(String type,String dateStr){
        SimpleDateFormat sdf = new SimpleDateFormat(type);
        try {
            return sdf.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * string 转 Calendar
     * @return
     */
    public static Calendar getFormatCalendar(String type,String dateStr){
        Date date = getFormatDate(type,dateStr);
        if (date==null)return null;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar;
    }

    /**
     * 获取日期 yyyy-MM
     * @return
     */
    public static String getFormatDate(Date date,String type){
        SimpleDateFormat sdf = new SimpleDateFormat(type);
        return sdf.format(date);
    }

    /**
     * 英文月份
     * @param InMonth
     * @return
     */
    public static String getMonthEN(int InMonth){
        String strParaMonthn = "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec";
        String[] strSubMonth = strParaMonthn.split("_");
        return strSubMonth[InMonth-1];
    }


}
